#include "APP_measure.h"

uint8_t temp_receive_buffer[9]={0}; //接收缓存
uint16_t temp_receive_len=8; //接收长度
uint8_t humi_receive_buffer[9]={0}; //接收缓存
uint16_t humi_receive_len=8; //接收长度

//获取温度
uint16_t APP_measure_getTemp(void){
    INF_485_send_mode();
    //发送指令
    //从站地址（1）功能码（1）寄存器地址（2）寄存器个数（2）CRC校验（2）
    uint8_t temp_send_buffer[8] = {0x01,0x04,0x00,0x00,0x00,0x01,0x31,0xCA}; 
    INF_485_send_data(temp_send_buffer,8);
    //接收数据
    INF_485_receive_mode();
    INF_485_receive_data(temp_receive_buffer,temp_receive_len);
    //解析数据
    //第四五字节为温度数据，单温摄氏度
    uint16_t temp_data = (temp_receive_buffer[3]<<8) + temp_receive_buffer[4];
    //处理数据
    return temp_data;
    // return 123;
}

//获取湿度
uint16_t APP_measure_getHumi(void){
    INF_485_send_mode();
    //发送指令
    //从站地址（1）功能码（1）寄存器地址（2）寄存器个数（2）CRC校验（2）
    uint8_t humi_send_buffer[8] = {0x01,0x04,0x02,0x00,0x00,0x01,0x60,0x0A}; 
    INF_485_send_data(humi_send_buffer,8);
    //接收数据
    INF_485_receive_mode();
    INF_485_receive_data(humi_receive_buffer,humi_receive_len);
    //解析数据
    //第4、第5字节为湿度数据，单位：%RH
    uint16_t humi_data = (humi_receive_buffer[3]<<8) + humi_receive_buffer[4];
    //处理数据
    return humi_data;
    // return 456;
}

